package com.xbao.controller;

import com.xbao.core.component.page.Pagination;
import com.xbao.core.http.CommRequest;
import com.xbao.core.http.CommResult;
import com.xbao.model.req.PeriodRuleReq;
import com.xbao.model.vo.PeriodRuleVo;
import com.xbao.service.PeriodRuleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * Created by qingshengzheng on 18/10/13.
 */
@Api(value = "/periodrule", tags = "periodrule")
@RequestMapping(value = "periodrule")
@Controller
@EnableAutoConfiguration
public class PeriodRuleController extends BaseController {
    @Resource
    private PeriodRuleService periodRuleService;

    @ApiOperation(value = "detail", notes = "detail")
    @RequestMapping(value = "/detail", method = RequestMethod.POST)
    @ResponseBody
    public CommResult detail(@RequestBody CommRequest<PeriodRuleReq> periodRuleCommRequest) {
        PeriodRuleVo vo=periodRuleService.detailPeriodRule(periodRuleCommRequest.getData().getId()
        );
        return new CommResult<PeriodRuleVo>(vo);
    }

    @ApiOperation(value = "update", notes = "update")
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    @ResponseBody
    public CommResult update(@RequestBody CommRequest<PeriodRuleReq> periodRuleCommRequest) {
        periodRuleService.modifyPeriodRule(periodRuleCommRequest.getData());
        return result();
    }


    @ApiOperation(value = "delete", notes = "delete")
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    @ResponseBody
    public CommResult delete(@RequestBody CommRequest<PeriodRuleReq> periodRuleCommRequest) {
        periodRuleService.deletePeriodRule(periodRuleCommRequest.getData().getId());
        return result();
    }

    @ApiOperation(value = "addPeriodRule", notes = "addPeriodRule")
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    @ResponseBody
    public CommResult addPeriodRule(@RequestBody CommRequest<PeriodRuleReq> periodRuleCommRequest) {
        periodRuleService.addPeriodRule(periodRuleCommRequest.getData());
        return result();
    }

    @ApiOperation(value = "listPeriodRule", notes = "listPeriodRule")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    @ResponseBody
    public CommResult listPeriodRule(@RequestBody CommRequest<PeriodRuleReq> periodRuleCommRequest) {
        List<PeriodRuleVo> vos= periodRuleService.queryPeriods(periodRuleCommRequest.getData());
        return new CommResult<List<PeriodRuleVo>>(vos);
    }


}
